unit AddEditServpodrazdLink;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dRoot, DB, StdCtrls, Buttons, ExtCtrls, ComCtrls, cxGraphics,
  cxCustomData, cxStyles, cxTL, cxMaskEdit, dxSkinsCore, dxSkinBlack,
  dxSkinBlue, dxSkinCaramel, dxSkinCoffee, dxSkinDarkSide,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinPumpkin,
  dxSkinSilver, dxSkinStardust, dxSkinSummer2008, dxSkinsDefaultPainters,
  dxSkinValentine, dxSkinXmas2008Blue, dxSkinscxPCPainter, cxFilter,
  cxData, cxDataStorage, cxEdit, cxDBData, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, cxSplitter, IBCustomDataSet,
  cxInplaceContainer, cxDBTL, cxTLData, IBQuery, IBUpdateSQL;

type
  TfmAddEditServpodrazdLink = class(TdlgRoot)
    qSD: TIBQuery;
    dsSD: TDataSource;
    dbtl: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn1: TcxDBTreeListColumn;
    qSDSDPARID: TIntegerField;
    qSDSDID: TIntegerField;
    qSDSDNAME: TIBStringField;
    cxSplitter1: TcxSplitter;
    dbglink: TcxGrid;
    tvlink: TcxGridDBTableView;
    dbglinkLevel1: TcxGridLevel;
    tvlinkSDNAME: TcxGridDBColumn;
    procedure qSDBeforeOpen(DataSet: TDataSet);
    procedure FormShow(Sender: TObject);
    procedure dbtlDblClick(Sender: TObject);
    procedure tvlinkDblClick(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    sdparid, stid: Integer;
  end;

var
  fmAddEditServpodrazdLink: TfmAddEditServpodrazdLink;

implementation
uses DBinv, InvProc, InvTypes;
{$R *.dfm}

procedure TfmAddEditServpodrazdLink.qSDBeforeOpen(DataSet: TDataSet);
begin
  inherited;
  qSD.ParamByName('sdparid').AsInteger := sdparid;
  dbtl.RootValue := sdparid;
end;

procedure TfmAddEditServpodrazdLink.FormShow(Sender: TObject);
begin
  inherited;
  qSD.Close;
  qSD.Open;
end;

procedure TfmAddEditServpodrazdLink.dbtlDblClick(Sender: TObject);
begin
  inherited;
  if qSD.IsEmpty then Exit;
   if dbtl.FocusedNode.HasChildren then Exit;
  if ( dlgDS.Dataset as TIBQuery).Locate('sdid', qSDSDID.AsInteger, []) then Exit;
  dlgDS.Dataset.Insert;

   dlgDS.Dataset.Edit;

   dlgDS.Dataset.fieldbyname('sdid').asInteger := qSDSDID.AsInteger;
   dlgDS.Dataset.fieldbyname('sdname').AsString := qSDSDNAME.AsString;
  dlgDS.Dataset.Post;
end;

procedure TfmAddEditServpodrazdLink.tvlinkDblClick(Sender: TObject);
begin
  inherited;
  if dlgDS.Dataset.IsEmpty then Exit;
  dlgDS.Dataset.Delete;
end;

procedure TfmAddEditServpodrazdLink.BitBtn1Click(Sender: TObject);
begin
  inherited;

  ModalResult := mrOk;
end;

end.

